using System;
using infoMECHANICA.NHibernateORM.CriteriaBuilder;

namespace infoMECHANICA.NHibernateORM.TestMappings
{
    /// <summary>
    /// Recorder of Employee class/Employees table
    /// </summary>
    [Serializable]
    public class EmployeeRec : CriteriaRecorder<EmployeeRec,Employee>
    {
        private ICriterionProperty<int> _EmployeeId;
        private CompanyRec _CompanyRec;
        private JobRec _JobRec;
        private ICriterionProperty<string> _FirstName;
        private ICriterionProperty<string> _LastName;
        private ICriterionProperty<DateTime> _DateOfBirth;
        private ICriterionProperty<int> _Salary;


        /// <summary>
        /// Recorder property for EmployeeId column (PRIMARY KEY!)
        /// </summary>
        public ICriterionProperty<int> EmployeeId
        {
            get 
            {
                if (this._EmployeeId == null)
                {
                    this._EmployeeId = new CriterionProperty<int>("EmployeeId", this);
                }
                
                return _EmployeeId; 
            }               
        }
        
        /// <summary>
        /// Gets the name of dto identifier property (when it's different than "Id")
        /// </summary>
        public override string GetIdPropertyName()
        {
            return "EmployeeId";
        }
 
        /// <summary>        
        /// Recorder for one-to-many relations between Companies and Employees
        /// </summary>        
        public virtual CompanyRec Company        
        {
            get
            {
                if (this._CompanyRec == null)
                {
                    this._CompanyRec = new CompanyRec(this);
                }
                
                return this._CompanyRec;
            }
            set
            {
                if (this._CompanyRec == null)
                {                    
                    this._CompanyRec = value;
                }
                else
                {
                    throw new RecorderAlreadyCreatedException();
                }
            }
        }
 
        /// <summary>        
        /// Recorder for one-to-many relations between Jobs and Employees
        /// </summary>        
        public virtual JobRec Job        
        {
            get
            {
                if (this._JobRec == null)
                {
                    this._JobRec = new JobRec(this);
                }
                
                return this._JobRec;
            }
            set
            {
                if (this._JobRec == null)
                {                    
                    this._JobRec = value;
                }
                else
                {
                    throw new RecorderAlreadyCreatedException();
                }
            }
        }
 
        /// <summary>
        /// Recorder property for FirstName column
        /// </summary>
        public ICriterionProperty<string> FirstName
        {
            get 
            {
                if (this._FirstName == null)
                {
                    this._FirstName = new CriterionProperty<string>("FirstName", this);
                }
                
                return _FirstName; 
            }               
        }        
 
        /// <summary>
        /// Recorder property for LastName column
        /// </summary>
        public ICriterionProperty<string> LastName
        {
            get 
            {
                if (this._LastName == null)
                {
                    this._LastName = new CriterionProperty<string>("LastName", this);
                }
                
                return _LastName; 
            }               
        }        
 
        /// <summary>
        /// Recorder property for DateOfBirth column
        /// </summary>
        public ICriterionProperty<DateTime> DateOfBirth
        {
            get 
            {
                if (this._DateOfBirth == null)
                {
                    this._DateOfBirth = new CriterionProperty<DateTime>("DateOfBirth", this);
                }
                
                return _DateOfBirth; 
            }               
        }        
 
        /// <summary>
        /// Recorder property for Salary column
        /// </summary>
        public ICriterionProperty<int> Salary
        {
            get 
            {
                if (this._Salary == null)
                {
                    this._Salary = new CriterionProperty<int>("Salary", this);
                }
                
                return _Salary; 
            }               
        }        


        /// <summary>
        /// Constructor, creates the recorder with no parent
        /// </summary>
        public EmployeeRec()
        {
        }
        
        /// <summary>
        /// Constuctor, creates CriteriaRecorder and sets its parent
        /// </summary>
        /// <param name="parent">Parent of this recorder</param>
        public EmployeeRec (ICriteriaRecorder parent)
            : base(parent)
        {
        }
    }
}